#ifndef __SCENE_EDITOR_DOCUMENT_H__
#define __SCENE_EDITOR_DOCUMENT_H__


#include "QDocument.h"
#include "QDictionary.h"
#include "SceneEditor.h"
#include "ImageInfo.h"


class SceneImageLoader;


class SceneEditorDoc : public QDocument
{
    Q_OBJECT
    Q_DISABLE_COPY(SceneEditorDoc)

signals:
    void loadingStarted(int);
    void loadingProgress(int, const QString &);
    void loadingFinished(int, const QString &);

    void savingStarted(int);
    void savingProgress(int, const QString &);
    void savingFinished(int, const QString &);

    void imageInserted(ImageInfo *info, QGraphicsPixmapItem *item, int mode);
    void imageDeleted(int index, qint64 cacheKey);
    void imagePositionAdjusted(int index, qint64 cacheKey, const QPoint &pos);
    void imageModeModified(int index, qint64 cacheKey, int mode);
    void imageOrderSwaped(int srcIdx, int dstIdx, qint64 srcKey, qint64 dstKey);

public slots:
    void onLoadingStarted();
    void onLoadingTotalStep(int total);
    void onLoadingProgress(int step, ImageInfo *info, int mode, QGraphicsPixmapItem *item);
    void onLoadingFinished(int result, const QString &msg);

    void onSavingStarted();
    void onSavingTotalStep(int total);
    void onSavingProgress(int step, const QString &file);
    void onSavingFinished(int result, const QString &msg);

public:
    SceneEditorDoc(QObject *parent = 0);
    virtual ~SceneEditorDoc();

    bool loadData();
    bool saveData();

    bool insertImage(const QString &filePath, ImageMode mode);

    bool deleteImageByIndex(int index);
    bool deleteImageByKey(qint64 cacheKey);

    bool adjustImagePositionByIndex(int index, const QPoint &pos);
    bool adjustImagePositionByKey(qint64 cacheKey, const QPoint &pos);

    bool modifyImageModeByIndex(int index, ImageMode mode);
    bool modifyImageModeByKey(qint64 cacheKey, ImageMode mode);

    bool swapImageOrder(int srcIdx, int dstIdx);

protected:
    bool loadImages();
    bool saveImages();

protected:  // from QDocument
    virtual bool onCreateDocument();
    virtual bool onOpenDocument();
    virtual bool onSaveDocument();
    virtual void onCloseDocument();

private:
    QDictionary         mSceneInfo;

    QImageInfoList      mBkgndInfoList;     /// 背景图信息
    QImageInfoList      mMaskInfoList;      /// 遮挡图信息
};


#endif  /*__SCENE_EDITOR_DOCUMENT_H__*/
